<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@ page import="com.semanticvoid.lifelogger.karma.search.interfaces.ISearch" %>
<%@ page import="com.semanticvoid.lifelogger.configuration.Constants" %>
<%@ page import="com.semanticvoid.lifelogger.configuration.ConfigManager" %>
<%@ page import="com.semanticvoid.lifelogger.entity.SearchHistoryEntity" %>
<%@ page import="java.util.Vector" %>
<%@ page import="java.util.Collection" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="com.semanticvoid.lifelogger.karma.search.factory.SearchFactory" %>

<%
ISearch searcher = (ISearch) session.getAttribute("searcher");
String query = (String) session.getAttribute("query");
String fromDate = (String) session.getAttribute("fdate");
String toDate = (String) session.getAttribute("tdate");
Vector<SearchHistoryEntity> searchHistoryResults = searcher.searchSearchHistory(query, fromDate, toDate);
%>
<div id="searchResults" style="overflow:auto; width:100%;">
    <table cellspacing="2" border="0" style="width:100%;">
    <tr>
        <td style="vertical-align: center; background-color: rgb(204, 204, 204);">
            <font size="2">&nbsp;<b>Search query results</b></font><br>
            <font size="1">&nbsp;&nbsp;<%= searchHistoryResults.size() %> result(s)</font>
        </td>
        <td style="vertical-align: center; background-color: rgb(204, 204, 204);" width="10px">
            <a href="#" onclick="toggle_visibility('searchResultsInner'); toggle_txt('searchResultsInner'); return false;"><font size="1"> <div id="searchResultsInnerTxt"> [hide] </div> </font></a>
        </td>
    </tr>
    
    <tr>
    <td colspan="2" style="background-color: #FFFFFF; border: #CCCCCC solid 1px">
        <div id="searchResultsInner" style="overflow:auto; width:100%; display: block;">
        <table cellspacing="2" border="0" style="width:100%;">
        <%
        if(searchHistoryResults.size() == 0) {
        %>
        <tr>
            <td>
                &nbsp;
            </td>    
        </tr>
        <tr>
            <td align="center">
                <b><font color="#000000">Zarro results found</font></b>
            </td>    
        </tr>
        <tr>
            <td>
                &nbsp;
            </td>    
        </tr>
        <%}%>
        
        <% 
        int i=0;
        Iterator itr = searchHistoryResults.iterator();
                        
        while(itr.hasNext()) {
        //for(int i=0; i<searchHistoryResults.size(); i++) {
    SearchHistoryEntity sEntity = (SearchHistoryEntity) itr.next();
        i++;
        %>
        <tr style="cursor: hand; color: #ffffff;"> 
            <td style="vertical-align: top; background-color: #cf9f66">
                <div>
                    <font color="#000000">&nbsp;<%= i %>. <a href="<%= sEntity.getLink() %>" title="<%= sEntity.getKeywords() %>"> <%= sEntity.getKeywords() %></font></a><br>
                    <font size="1">&nbsp;&nbsp;<%= sEntity.getPubDate().getTime().toGMTString() %></font>
                </div>
            </td>
        </tr>
        <% } %>
        </table>
    </div>
</td>
</tr>
</table>
</div>